home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 3.2 / Ham Radio Version 3.2 (Chestnut CD-ROMs)(1993).ISO / packet / n17jsrc / mkname.c < prev    next >
C/C++ Source or Header  |  1991-08-31  |  2KB  |  69 lines

  1. /* routines to override the standard Borland library routines */
  2. /* PA0GRI , N1BEE , aparent origin PE1CHL */
  3. /* Compile into _TEXT segment with -zC_TEXT */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <io.h>
  8. #include "global.h"
  9.  
  10. #ifdef __TURBOC__
  11.  
  12. char *getnenv __ARGS((char *name));    /* In pc.c */
  13. #ifdef __BORLANDC__
  14. char far * near pascal __MKNAME __ARGS((char far *tmpname,unsigned int tmpnum));
  15. #else
  16. char *pascal __MKNAME __ARGS((char *tmpname,unsigned int tmpnum));
  17. #endif
  18.  
  19. unsigned int _tmpnum = 0;
  20.  
  21. /* low-level routines used by tmpnam, fixed to use TMP environment variable */
  22.  
  23. #ifdef __BORLANDC__
  24. char far * near pascal __MKNAME (tmpname,tmpnum)  /* Turbo C++ acc. n1bee */
  25. char far *tmpname;
  26. #else
  27. char *pascal __MKNAME (tmpname,tmpnum)          /* The "standard compiler" */
  28. char *tmpname;
  29. #endif
  30. unsigned int tmpnum;
  31. {
  32.     char *tmpdir,*p;
  33.     static char staticname[80];
  34.  
  35.     if (tmpname == NULL)
  36.         tmpname = staticname;
  37.  
  38.     p = tmpdir = getnenv("TMP");        /* get tempdir name */
  39.     if (p[0] != '\0')
  40.         p += strlen(p) - 1;        /* point to last character */
  41.  
  42.     sprintf(tmpname,"%s%sTMP%u.$$$",tmpdir,
  43.             ((*p != '/' && *p != '\\')? "/":""),tmpnum);
  44.  
  45.     return tmpname;
  46. }
  47.  
  48. /* new tmpnam function.     calls above routine to generate the name, but */
  49. /* is otherwise the same as the tmpnam() in the library. */
  50.  
  51. char *tmpnam (name)
  52. char *name;
  53. {
  54.     do
  55.     {
  56.         if (_tmpnum == 0xffff)
  57.      _tmpnum = 2;
  58.         else
  59.      ++_tmpnum;
  60.  
  61.         name = __MKNAME(name,_tmpnum);
  62.     }
  63.     while (access(name,0) != -1);
  64.  
  65.     return name;
  66. }
  67.  
  68. #endif
  69.